package com.ruoyi.amuse.clubs.controller;


import com.ruoyi.amuse.clubs.domain.Club;
import com.ruoyi.amuse.clubs.service.IClubService;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 社团管理Controller
 * 
 * @author juwujie
 * @date 2024-07-19
 */
@RestController
@RequestMapping("/clubs/clubs")
public class ClubController extends BaseController
{
    @Autowired
    private IClubService clubService;

    /**
     * 查询社团管理列表
     */
    @RequiresPermissions("clubs:clubs:list")
    @GetMapping("/list")
    public TableDataInfo list(Club club)
    {
        startPage();
        List<Club> list = clubService.selectClubList(club);
        return getDataTable(list);
    }

    /**
     * 导出社团管理列表
     */
    @RequiresPermissions("clubs:clubs:export")
    @Log(title = "社团管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Club club)
    {
        List<Club> list = clubService.selectClubList(club);
        ExcelUtil<Club> util = new ExcelUtil<Club>(Club.class);
        util.exportExcel(response, list, "社团管理数据");
    }

    /**
     * 获取社团管理详细信息
     */
    @RequiresPermissions("clubs:clubs:query")
    @GetMapping(value = "/{clubId}")
    public AjaxResult getInfo(@PathVariable("clubId") Long clubId)
    {
        return success(clubService.selectClubByClubId(clubId));
    }

    /**
     * 新增社团管理
     */
    @RequiresPermissions("clubs:clubs:add")
    @Log(title = "社团管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Club club)
    {
        return toAjax(clubService.insertClub(club));
    }

    /**
     * 修改社团管理
     */
    @RequiresPermissions("clubs:clubs:edit")
    @Log(title = "社团管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Club club)
    {
        return toAjax(clubService.updateClub(club));
    }

    /**
     * 删除社团管理
     */
    @RequiresPermissions("clubs:clubs:remove")
    @Log(title = "社团管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{clubIds}")
    public AjaxResult remove(@PathVariable Long[] clubIds)
    {
        return toAjax(clubService.deleteClubByClubIds(clubIds));
    }
}
